﻿/* 用于生成如下html5片段
  <datalist id="browsers">
  <option value="Internet Explorer">
  <option value="Firefox">
  <option value="Chrome">
  <option value="Opera">
  <option value="Safari">
  </datalist>
*/

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;
using WalkingTec.Mvvm.Core;

namespace ReaWTM.LayuiHelper
{

	[HtmlTargetElement("wt:datalist", Attributes = "id,items", TagStructure = TagStructure.WithoutEndTag)]
	public class DataListTagHelper : BaseElementTag
	{
		public List<ComboSelectListItem> Items { get; set; }
		public override void Process(TagHelperContext context, TagHelperOutput output)
		{
			output.TagName = "datalist";
			output.TagMode = TagMode.StartTagAndEndTag;
			output.Attributes.Add("id", Id);
			if (Items != null)
			{
				foreach (var item in Items)
				{
					output.Content.AppendHtml($"<option value='{item.Value}'>{item.Text}</option>");
				}
			}
		}

	}
}
